package com.lemon.smartsafety.ui.adapter.profile;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.entity.event.user.MyHeaderImgEvent;
import com.lemon.smartsafety.entity.event.user.MyNoticeEvent;
import com.lemon.smartsafety.entity.event.user.MyScoreEvent;
import com.lemon.smartsafety.entity.user.ProfileBaseModel;
import com.lemon.smartsafety.entity.user.ProfileHeadModel;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.utils.ImgLoadUtil;

import de.hdodenhof.circleimageview.CircleImageView;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/1/27.
 */
public class ProfileHeadItemView implements AdapterItem<ProfileBaseModel> {

    private CircleImageView profileImageStar;
    private TextView        mTextUserName, mTextUserType;

    private LinearLayout rippleMyNotice, rippleMyScore;


    @Override
    public int getLayoutResId() {
        return R.layout.item_profile_head_view;
    }

    @Override
    public void bindViews(View root) {
        profileImageStar = (CircleImageView) root.findViewById(R.id.profileImageStar);
        mTextUserName = (TextView) root.findViewById(R.id.tvUserName);
        mTextUserType = (TextView) root.findViewById(R.id.tvUserType);


        rippleMyNotice = (LinearLayout) root.findViewById(R.id.rippleMyNotice);
        rippleMyScore = (LinearLayout) root.findViewById(R.id.rippleMyScore);
    }

    @Override
    public void setViews() {
        rippleMyNotice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyNoticeEvent event = new MyNoticeEvent();
                event.setTag(ProfileHeadItemView.class.getName());
                AppService.getBus().post(event);
            }
        });
        rippleMyScore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyScoreEvent event = new MyScoreEvent();
                event.setTag(ProfileHeadItemView.class.getName());
                AppService.getBus().post(event);
            }
        });

        profileImageStar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyHeaderImgEvent event = new MyHeaderImgEvent();
                event.setTag(ProfileHeadItemView.class.getName());
                AppService.getBus().post(event);
            }
        });


     /*   rippleMyNotice.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                MyNoticeEvent event = new MyNoticeEvent();
                event.setTag(ProfileHeadItemView.class.getName());
                AppService.getBus().post(event);
            }
        });
        rippleMyScore.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                MyScoreEvent event = new MyScoreEvent();
                event.setTag(ProfileHeadItemView.class.getName());
                AppService.getBus().post(event);
            }
        });*/
    }

    @Override
    public void handleData(ProfileBaseModel profileBaseModel, int position) {
        if (profileBaseModel.getViewType() == ProfileViewType.TYPE_HEAD) {
            ProfileHeadModel profileHeadModel = (ProfileHeadModel) profileBaseModel;
            mTextUserName.setText(profileHeadModel.getUserName());
            mTextUserType.setText(profileHeadModel.getUserType());
            if(!CommonUtil.strIsEmpty(profileHeadModel.getIconPath())){
                try {
                    ImgLoadUtil.setImgPath(profileHeadModel.getIconPath(), profileImageStar);
                    //profileImageStar.setImageURI(Uri.parse(profileHeadModel.getIconPath()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                profileImageStar.setImageDrawable(IApplication.getAppResources().getDrawable(R.mipmap.user_no_photo));
            }
          /*  else{
                ImgLoadUtil.setImgPath("http://img2.pconline.com.cn/pconline/0706/19/1038447_34.jpg", profileImageStar);
            }*/
        }

    }

}
